package com.jumi.microservice.controller.admin;

/**
 * @author Scw
 * @Date 2020-08-08 17:09
 */

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.reissue.*;
import com.jumi.microservice.service.admin.AdminReissueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-05 11:38
 */
@Api(tags = {"后台售后管理--补发相关接口"})
@RestController
@RequestMapping("/admin/reissue")
public class AdminReissueController extends BaseController {
    @Resource
    private AdminReissueService adminReissueService;

    @PostMapping("/exportExcel")
    @ApiOperation("导出excel")
    public void exportBfExcel(ExportReissueListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportReissueListResponse> exportReissueListResponseExportExcelCommonResponse = adminReissueService.exportExcel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportReissueListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportReissueListResponse.class).sheet("sheet1").doWrite(exportReissueListResponseExportExcelCommonResponse.getData());
    }

    @GetMapping("/reissueList")
    @ApiOperation("补发列表")
    TableDataInfo<ReissueListResponse> reissueList(ReissueListRequest reissueListRequest) {
        return adminReissueService.reissueList(reissueListRequest);
    }

    @PostMapping(value = "/addReissue")
    @ApiOperation("补发添加")
    public ResponseResult<Boolean> addReissue(ReissueAddRequest reissueAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        reissueAddRequest.setOperatorId(getUid());
        reissueAddRequest.setOperatorName(getUserName());
        result.setData(adminReissueService.addReissue(reissueAddRequest));
        return result;
    }

    @PostMapping(value = "/cancelReissue")
    @ApiOperation("补发取消")
    public ResponseResult<Boolean> cancelReissue(ReissueCancelRequest reissueCancelRequest, ReissueOperateRequest reissueOperateRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        reissueCancelRequest.setOperatorId(getUid());
        reissueCancelRequest.setOperatorName(getUserName());
        result.setData(adminReissueService.cancelReissue(reissueCancelRequest, reissueOperateRequest));
        return result;
    }

    @GetMapping(value = "/reissueInfo")
    @ApiOperation("补发详情")
    public ResponseResult<ReissueInfoResponse> reissueInfo(ReissueOperateRequest reissueOperateRequest) {
        ResponseResult<ReissueInfoResponse> result = new ResponseResult<>();
        result.setData(adminReissueService.reissueInfo(reissueOperateRequest));
        return result;
    }

    @GetMapping("/reissueReason/dictionary")
    @ApiOperation("补发原因对照字典")
    public ResponseResult<Map<Integer, String>> getReissueReason() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminReissueService.getReissueReason());
        return result;
    }

    @GetMapping("/reissueCheckStatus/dictionary")
    @ApiOperation("补发审核状态对照字典")
    public ResponseResult<Map<Integer, String>> getReissueCheckStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminReissueService.getReissueCheckStatus());
        return result;
    }

    @GetMapping("/reissueStatus/dictionary")
    @ApiOperation("补发状态对照字典")
    public ResponseResult<Map<Integer, String>> getReissueStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminReissueService.getReissueStatus());
        return result;
    }

    @GetMapping("/reissueType/dictionary")
    @ApiOperation("补发类型对照字典")
    public ResponseResult<Map<Integer, String>> getReissueType() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminReissueService.getReissueType());
        return result;
    }
}
